package com.rachel.materialdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.rachel.materialdemo.R;
import com.rachel.materialdemo.ToolUtils;
import com.rachel.materialdemo.adapter.LBaseAdapter;
import com.rachel.materialdemo.bean.HomeBean;

import java.util.ArrayList;
import java.util.List;

public class ListViewActivity extends AppCompatActivity {
    private static final String TAG = "zsr";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        List<HomeBean> homeBeens =  new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            HomeBean bean = new HomeBean();
            bean.type = ToolUtils.TYPE_ONE;
            bean.title = "test: "+i;
            bean.resid = R.mipmap.image5;
            homeBeens.add(bean);
        }
        for (int i = 0; i < 2; i++) {
            HomeBean bean = new HomeBean();
            bean.type = ToolUtils.TYPE_TWO;
            bean.title = "测试: "+i;
            bean.resid = R.mipmap.image5;
            bean.residtwo = R.mipmap.beauty;
            homeBeens.add(bean);
        }
        for (HomeBean bean : homeBeens) {
            Log.d(TAG, "onCreate: "+bean.type+" "+bean.title);
        }

        ListView listView = (ListView) findViewById(R.id.listview);
        LBaseAdapter adapter = new LBaseAdapter(this,homeBeens);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListViewActivity.this, "点击了: "+position, Toast.LENGTH_SHORT).show();
            }
        });
        TextView text = new TextView(this);
        text.setText("listview复杂布局");

        listView.addHeaderView(text);

    }
}
